using ASP;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;
public class Search_Shop : Shop, IRequiresSessionState
{
	protected UserControls_cmpy_Top Top1;
	protected Literal Literaltop_menu;
	protected Literal ShowShopClassList_Literal;
	protected HtmlInputText SearchShopName;
	protected HtmlInputText SearchSalerName;
	protected DropDownList ProvinceCity;
	protected Button SearchShopButton;
	protected Repeater Repeater1;
	protected HtmlTable tError;
	protected AspNetPager AspNetPager1;
	protected UserControls_CMYP_Foot Foot1;
	protected HtmlForm form1;
	private Shop_Shop _shop;
	private Shop_City _city;
	private int _classID;
	private string _shopName = "-1";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public Shop_Shop Shop
	{
		get
		{
			Shop_Shop shop;
			if (this._shop == null)
			{
				this._shop = new Shop_Shop(this.conn);
				shop = this._shop;
			}
			else
			{
				shop = this._shop;
			}
			return shop;
		}
	}
	protected Shop_City m_city
	{
		get
		{
			Shop_City city;
			if (this._city == null)
			{
				this._city = new Shop_City(this.conn);
				city = this._city;
			}
			else
			{
				city = this._city;
			}
			return city;
		}
	}
	public int Stamp
	{
		get
		{
			return (int)this.Session["Stamp"];
		}
		set
		{
			this.Session["Stamp"] = value;
		}
	}
	public int ClassID
	{
		get
		{
			int classID;
			if (!string.IsNullOrEmpty(base.Request.QueryString["ClassID"]))
			{
				this._classID = Convert.ToInt32(base.Request.QueryString["ClassID"]);
				classID = this._classID;
			}
			else
			{
				classID = this._classID;
			}
			return classID;
		}
		set
		{
			this._classID = value;
		}
	}
	public string ShopName
	{
		get
		{
			string text = base.Request.QueryString["ShopName"];
			string shopName;
			if (!string.IsNullOrEmpty(text))
			{
				this._shopName = text;
				shopName = this._shopName;
			}
			else
			{
				shopName = this._shopName;
			}
			return shopName;
		}
		set
		{
			this._shopName = value;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.ShowCityArea();
		this.BindTopList();
		if (!base.IsPostBack)
		{
			this.Session["Stamp"] = 1;
			this.BindClassList();
			this.Province();
			this.BindShopList();
		}
	}
	public void BindShopList()
	{
		this.Session["Stamp"] = 1;
		if (this.ShopName != "-1")
		{
			this.AspNetPager1.RecordCount = this.Shop.GetHLShopCount(this.ShopName, "", "请选择", "").Rows.Count;
			int pageSize = this.AspNetPager1.PageSize = 13;
			int pageIndex;
			if (this.AspNetPager1.CurrentPageIndex < 1)
			{
				pageIndex = 1;
			}
			else
			{
				pageIndex = this.AspNetPager1.CurrentPageIndex;
			}
			DataTable hLShopBySearch = this.Shop.GetHLShopBySearch(pageIndex, pageSize, this.ShopName, "", "请选择", "");
			if (hLShopBySearch != null && hLShopBySearch.Rows.Count != 0)
			{
				this.Repeater1.DataSource = hLShopBySearch;
				this.tError.Visible = false;
			}
			else
			{
				this.tError.Visible = true;
			}
			this.Repeater1.DataBind();
		}
		else
		{
			if (this.ClassID != -1)
			{
				this.AspNetPager1.RecordCount = this.Shop.GetHLShopCount("", "", "请选择", this.ClassID.ToString()).Rows.Count;
				int pageSize = this.AspNetPager1.PageSize = 13;
				int pageIndex;
				if (this.AspNetPager1.CurrentPageIndex < 1)
				{
					pageIndex = 1;
				}
				else
				{
					pageIndex = this.AspNetPager1.CurrentPageIndex;
				}
				DataTable hLShopBySearch = this.Shop.GetHLShopBySearch(pageIndex, pageSize, "", "", "请选择", this.ClassID.ToString());
				if (hLShopBySearch != null && hLShopBySearch.Rows.Count != 0)
				{
					this.Repeater1.DataSource = hLShopBySearch;
					this.tError.Visible = false;
				}
				else
				{
					this.tError.Visible = true;
				}
				this.Repeater1.DataBind();
			}
		}
	}
	public void Province()
	{
		this.ProvinceCity.DataSource = this.m_city.GetAllProvince();
		this.ProvinceCity.DataTextField = "Province";
		this.ProvinceCity.DataValueField = "Province";
		this.ProvinceCity.DataBind();
		this.ProvinceCity.Items.Insert(0, new ListItem("请选择", "0"));
	}
	public void BindTopList()
	{
		string text = "";
		Shop_Class shop_Class = new Shop_Class(this.conn);
		DataTable rootClass = shop_Class.GetRootClass();
		text += "<a href='Search_Shop.aspx'>所有分类</a>";
		if (rootClass != null && rootClass.Rows.Count > 0)
		{
			for (int i = 0; i < rootClass.Rows.Count; i++)
			{
				int num = Convert.ToInt32(rootClass.Rows[i]["Classid"].ToString());
				if (this.ClassID == num)
				{
					text = text + "<span>&nbsp;</span>" + rootClass.Rows[i]["ClassName"].ToString();
				}
			}
		}
		this.Literaltop_menu.Text = text;
	}
	public void BindClassList()
	{
		string text = "";
		Shop_Class shop_Class = new Shop_Class(this.conn);
		DataTable rootClass = shop_Class.GetRootClass();
		if (rootClass != null && rootClass.Rows.Count > 0)
		{
			for (int i = 0; i < rootClass.Rows.Count; i++)
			{
				if (!(rootClass.Rows[i]["ClassName"].ToString() == "服务商品") && !(rootClass.Rows[i]["ClassName"].ToString() == "创美商品"))
				{
					int parentID = Convert.ToInt32(rootClass.Rows[i]["Classid"].ToString());
					DataTable childClassByParnetID = shop_Class.GetChildClassByParnetID(parentID);
					text += " <dl class='sidebar_list'><dt class=bg_color1>";
					string text2 = text;
					text = string.Concat(new string[]
					{
						text2,
						"<a href='Search_Shop.aspx?ClassID=",
						rootClass.Rows[i]["Classid"].ToString(),
						"'>",
						rootClass.Rows[i]["ClassName"].ToString(),
						"</a></dt>"
					});
					if (childClassByParnetID != null && rootClass.Rows.Count > 0)
					{
						for (int j = 0; j < childClassByParnetID.Rows.Count; j++)
						{
							text2 = text;
							text = string.Concat(new string[]
							{
								text2,
								"<dd><a href='ProductList.aspx?ClassID=",
								childClassByParnetID.Rows[j]["Classid"].ToString(),
								"'>",
								childClassByParnetID.Rows[j]["ClassName"].ToString(),
								"</a></dd>"
							});
						}
					}
					text += "</dl>";
				}
			}
		}
		this.ShowShopClassList_Literal.Text = text;
	}
	protected void SearchShopButton_Click(object sender, EventArgs e)
	{
		this.SearchList();
		this.Session["Stamp"] = 2;
	}
	public void SearchList()
	{
		this.AspNetPager1.RecordCount = this.Shop.GetHLShopCount(this.SearchShopName.Value, this.SearchSalerName.Value, this.ProvinceCity.SelectedItem.Text, "").Rows.Count;
		int pageSize = this.AspNetPager1.PageSize = 13;
		int pageIndex;
		if (this.AspNetPager1.CurrentPageIndex < 1)
		{
			pageIndex = 1;
		}
		else
		{
			pageIndex = this.AspNetPager1.CurrentPageIndex;
		}
		DataTable hLShopBySearch = this.Shop.GetHLShopBySearch(pageIndex, pageSize, this.SearchShopName.Value, this.SearchSalerName.Value, this.ProvinceCity.SelectedItem.Text, "");
		if (hLShopBySearch != null && hLShopBySearch.Rows.Count != 0)
		{
			this.Repeater1.DataSource = hLShopBySearch;
			this.tError.Visible = false;
		}
		else
		{
			this.tError.Visible = true;
		}
		this.Repeater1.DataBind();
	}
	protected void AspNetPager1_PageChanged(object sender, EventArgs e)
	{
		if (this.Stamp == 1)
		{
			this.BindShopList();
		}
		else
		{
			if (this.Stamp == 2)
			{
				this.SearchList();
			}
		}
	}
	public int getSalerCredit(int UserID)
	{
		Shop_Product shop_Product = new Shop_Product();
		return shop_Product.BindSaleCrediet(UserID);
	}
	public int getProductCount(object ShopID)
	{
		return this.Shop.GetProductCountByShopID(Convert.ToInt32(ShopID));
	}
	public string getLinkUser(object UserID)
	{
		string text = "";
		DataTable dataTable = this.conn.GetDataTable("select OICQ,Taobaowangwang,* from dbo.HL_UserInfo where UserID=" + Convert.ToInt32(UserID));
		if (dataTable != null && dataTable.Rows.Count != 0)
		{
			if (!string.IsNullOrEmpty(dataTable.Rows[0]["OICQ"].ToString()))
			{
				text += "<a target='_blank' href='http://wpa.qq.com/msgrd?V=1&amp;Uin=1036084950&amp;Site=&amp;Menu=yes' class='m_shopname'>\r\n                                                            <img border='0' title='QQ' onerror='this.src='../Images/QQerror.gif' src='http://wpa.qq.com/pa?p=1:1036084950:4'>\r\n                                                            </a>";
			}
			if (!string.IsNullOrEmpty(dataTable.Rows[0]["Taobaowangwang"].ToString()))
			{
				text += "<a class='m_shopname' target='_blank' href='http://amos.im.alisoft.com/msg.aw?v=2&amp;site=cntaobao&amp;s=1&amp;charset=utf-8&amp;uid=1036084950'>\r\n                                                            <img alt='点击这里给我发消息' src='Skin/productlistStyle/images/list_list_22.png'>\r\n                                                            </a>";
			}
		}
		return text;
	}
}
